package com.itheima.handler;

import com.itheima.entity.Result;
import com.itheima.entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @PackageName com.itheima.handler
 * @ProjectName Ceres-Work
 * @Created by Chanly on 2020/10/14 21:40
 **/
@ControllerAdvice
public class BaseExcrptionHandler {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e){
        if(e instanceof ServiceException){
            //处理的业务逻辑
            return new Result(false,400,e.getMessage());
        }
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR,e.getMessage());
    }
}
